<?php
/**
 * Created by PhpStorm.
 * User: FEIFEI
 * Date: 2018/7/30
 * Time: 10:02
 */

namespace App\Http\Controllers;
use App\Common\lib\Util;
use Illuminate\Http\Request;
use DB;
class DealController extends Controller{
    //B端交易
    public function B_deal(Request $request){

        if ( $request->ajax() ) {

            if ( isset( $request->rank ) ) {
                $url = "/api/clientuser/statistical?type=".$request->type."&page=".$request->page."&rows=".$request->rows."&rank=".$request->rank;
            } elseif ( isset( $request->like ) ) {
                $url = "/api/clientuser/statistical?type=".$request->type."&page=".$request->page."&rows=".$request->rows."&like=".$request->like;
//                dump(DB::getQueryLog());
            } else {
                $url = "/api/clientuser/statistical?type=".$request->type."&page=".$request->page."&rows=".$request->rows;
            }
            $response = Util::toCurl($url, [], 20);
            $data = json_decode($response, true);
            return $data;
//            var_dump($data);

        }else{
            return view('deal.b_deal');
        }

    }



    //B端交易详情
    public function b_deal_details(Request $request){

        if ( $request->ajax() ) {

            if ( isset( $request->rank ) ) {
                $url = "/api/clientuser/statistical/detail?type=2&id=".$request->id."&page=".$request->pages."&rows=".$request->pageSize."&rank=".$request->rank;
            } elseif ( isset( $request->like ) ) {
                $url = "/api/clientuser/statistical/detail?type=2&id=".$request->id."&page=".$request->pages."&rows=".$request->pageSize."&like=".$request->like;
//                dump(DB::getQueryLog());
            } elseif (isset( $request->startTime )){
                $url = "/api/clientuser/statistical/detail?type=2&id=".$request->id."&page=".$request->pages."&rows=".$request->pageSize."&startDate=".strtotime($request->startTime)."&endDate=".strtotime($request->endTime);
            }else {
                $url = "/api/clientuser/statistical/detail?type=2&id=".$request->id."&page=".$request->pages."&rows=".$request->pageSize;
            }
            $response = Util::toCurl($url, [], 20);
            $data = json_decode($response, true);
            return $data;
//            var_dump($data);

        }else{
            $id=$request->id;
            return view('deal.b_deal_details',[
                'id'=>$id
            ]);
        }

    }

    //C端交易
    public function C_deal(Request $request){

        if ( $request->ajax() ) {

            if ( isset( $request->rank ) ) {
                $url = "/api/clientuser/statistical?type=1&page=".$request->page."&rows=".$request->rows."&rank=".$request->rank;
            } elseif ( isset( $request->like ) ) {
                $url = "/api/clientuser/statistical?type=1&page=".$request->page."&rows=".$request->rows."&like=".$request->like;
//                dump(DB::getQueryLog());
            } else {
                $url = "/api/clientuser/statistical?type=1&page=".$request->page."&rows=".$request->rows;
            }
            $response = Util::toCurl($url, [], 20);
            $data = json_decode($response, true);
            return $data;
//            var_dump($data);

        }else{
            return view('deal.c_deal');
        }

    }



    //C端交易详情
    public function c_deal_details(Request $request){

        if ( $request->ajax() ) {

            if ( isset( $request->rank ) ) {
                $url = "/api/clientuser/statistical/detail?type=1&id=".$request->id."&page=".$request->pages."&rows=".$request->pageSize."&rank=".$request->rank;
            } elseif ( isset( $request->like ) ) {
                $url = "/api/clientuser/statistical/detail?type=1&id=".$request->id."&page=".$request->pages."&rows=".$request->pageSize."&like=".$request->like;
//                dump(DB::getQueryLog());
            } elseif (isset( $request->startTime )){
                $url = "/api/clientuser/statistical/detail?type=1&id=".$request->id."&page=".$request->pages."&rows=".$request->pageSize."&startDate=".strtotime($request->startTime)."&endDate=".strtotime($request->endTime);
            }else {
                $url = "/api/clientuser/statistical/detail?type=1&id=".$request->id."&page=".$request->pages."&rows=".$request->pageSize;
            }
            $response = Util::toCurl($url, [], 20);
            $data = json_decode($response, true);
            return $data;
//            var_dump($data);

        }else{
            $id=$request->id;
            return view('deal.c_deal_details',[
                'id'=>$id
            ]);
        }

    }







}